# import talib
import akshare as ak


class Stock:
    _symbol: str = '300458'
    _start_date: str = '2023-01-17 09:00:00'
    _end_date: str = '2023-05-17 18:00:00'
    _period: str = '30'
    _adjust: str = ''

    def __init__(self, symbol='', start_date='', end_date='', period='', adjust='') -> None:
        if symbol:
            self._symbol = symbol

        if start_date:
            self._start_date = start_date

        if end_date:
            self._end_date = end_date

        if period:
            self._period = period

        if adjust:
            self._adjust = adjust

    # 个股
    def getSingle(self):
        df = ak.stock_zh_a_hist_min_em(
            symbol=self._symbol, start_date=self._start_date, end_date=self._end_date, period=self._period, adjust=self._adjust)

        # Step2： 利用Pandas 计算MACD

        # short_ema = df['收盘'].ewm(span=12).mean()
        # long_ema = df['收盘'].ewm(span=26).mean()
        # df.loc[:, 'DIFF'] = short_ema - long_ema
        # df.loc[:, 'DEA'] = df['DIFF'].ewm(span=9).mean()
        # df.loc[:, 'MACD'] = 2 * (df['DIFF'] - df['DEA'])

        # Step3：利用talib 计算MACD

        #df['talib_DIFF'], df['talib_DEA'], df['talib_MACD'] = talib.MACD(df['收盘'].values)
        #df['talib_MACD'] *= 2  # 国内MACD需要乘以2

        return df

    # 板块
    def getBanKuai(self):
        df = ak.stock_board_industry_hist_min_em(
            symbol=self._symbol, period=self._period)

        # Step2： 利用Pandas 计算MACD

        # short_ema = df['收盘'].ewm(span=12).mean()
        # long_ema = df['收盘'].ewm(span=26).mean()
        # df.loc[:, 'DIFF'] = short_ema - long_ema
        # df.loc[:, 'DEA'] = df['DIFF'].ewm(span=9).mean()
        # df.loc[:, 'MACD'] = 2 * (df['DIFF'] - df['DEA'])

        # Step3：利用talib 计算MACD

        #df['talib_DIFF'], df['talib_DEA'], df['talib_MACD'] = talib.MACD(df['收盘'].values)
        #df['talib_MACD'] *= 2  # 国内MACD需要乘以2

        return df
